//
//  MMGSocketMsgModel.m
//  MyApp
//
//  Created by Don on 2017/8/29.
//  Copyright © 2017年 com.memego. All rights reserved.
//

#import "MMGSocketMsgModel.h"
#import "MMGConstSocketMsgType.h"
#import "MMGConstSocketMsgKey.h"

@implementation MMGSocketMsgModel

+ (MMGSocketMsgModel *)modelFromDataJson:(id)data {
    
    NSError *error = nil;
    return [MTLJSONAdapter modelOfClass:[MMGSocketMsgModel class] fromJSONDictionary:data error:&error];
}

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{@"code":kMMG_SOCKET_MSG_CODE,
             @"type":kMMG_SOCKET_MSG_TYPE,
             @"data":kMMG_SOCKET_MSG_DATA,
             @"timestamp":kMMG_SOCKET_MSG_TIMESTAMP};
}

+ (NSValueTransformer *)typeJSONTransformer {
    return [NSValueTransformer mtl_valueMappingTransformerWithDictionary:
  @{
//    kMMG_SOCKET_MSG_SYNC_TIME : @(EMMMGSocketMsgAckTypeSyncTime),
    kMMG_SOCKET_MSG_USER_LOGIN_ACK : @(EMMMGSocketMsgAckTypeLogin),
    kMMG_SOCKET_MSG_CONNECT_ACK:@(EMMMGSocketMsgAckTypeSocketConnected),
    kMMG_SOCKET_MSG_CONNECT_DEVICE_ACK : @(EMMMGSocketMsgAckTypeConnectedDevice),
    kMMG_SOCKET_MSG_RESERVE_GAME_ACK  : @(EMMMGSocketMsgAckTypeReserveGame),
    kMMG_SOCKET_MSG_READY_START_GAME_ACK  : @(EMMMGSocketMsgAckTypeReadyStartGame),
    kMMG_SOCKET_MSG_START_GAME_ACK  : @(EMMMGSocketMsgAckTypeStartGame),
    kMMG_SOCKET_MSG_CONTROL_DEVICE_ACK  : @(EMMMGSocketMsgAckTypeControlDevice),
    kMMG_SOCKET_MSG_DOWN_CLAW_ACK  : @(EMMMGSocketMsgAckTypeDownClaw),
    kMMG_SOCKET_MSG_WIN_PRIZE : @(EMMMGSocketMsgAckTypeWinPraize),//已经过期参数
    kMMG_SOCKET_MSG_WIN_PRIZE_ACK : @(EMMMGSocketMsgAckTypeWinPraizeAck),
    kMMG_SOCKET_MSG_HEARTBEAT_ACK : @(EMMMGSocketMsgAckTypeHeartbeat),
    
    kMMG_SOCKET_MSG_CANCEL_GAME_ACK : @(EMMMGSocketMsgAckTypeCancelGame),
    kMMG_SOCKET_MSG_DEVICE_STATISTICS_ACK : @(EMMMGSocketMsgAckTypeDeviceStatistics),
    kMMG_SOCKET_MSG_USER_ACCESS_AMOUNT_ACK : @(EMMMGSocketMsgAckTypeUserAccessAmount)
                                                                           }];
}
- (void)setNilValueForKey:(NSString *)key {
    if ([key isEqualToString:kMMG_SOCKET_MSG_DATA]) {
        self.data = @"";
    }else if ([key isEqualToString:kMMG_SOCKET_MSG_TYPE]){
        self.type = EMMMGSocketMsgAckTypeNone;
    }else{
        [super setNilValueForKey:key];
    }
}

@end
